#pragma once

#include <iostream>
#include <fstream>
#include <cassert>
#include <string>
#include <vector>
#include <unordered_map>
//#include <boost/filesystem.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string.hpp>





class docInfo
{
public:
    std::string docTitle_;
    std::string docUrl_;
    std::string docContent_;
};

namespace common
{

    bool Read(const std::string& input_path, std::string* content) 
    {
        std::ifstream file(input_path.c_str(), std::ios::binary);
        if (!file.is_open()) 
        {
            return false;
        }
        file.seekg(0, file.end);
        int length = file.tellg();
        file.seekg(0, file.beg);
        // content->resize(length + 1);
        content->resize(length);
        file.read(const_cast<char*>(content->data()), length);
        file.close();
        return true;
    }
    void WriteOut(const docInfo& doc, std::ofstream& out)
    {
        out << doc.docTitle_ << "\3" << doc.docUrl_ << "\3" << doc.docContent_ << "\n";
    }
    void SplitLineToDoc(docInfo* doc, const std::string& line, const std::string& split_char)
    {
        std::vector<std::string> output;
        boost::split(output, line, boost::is_any_of(split_char), boost::token_compress_off);
        if(output.size() == 3)
        {
            doc->docTitle_ = output[0];
            doc->docUrl_ = output[1];
            doc->docContent_ = output[2];
        }
        
    }

};

